<template>
	<!-- 当mescroll-body写在子组件时,父页面需引入mescroll-comp.js的mixins -->
	<mescroll-body ref="mescrollRef" top="270" @init="mescrollInit" @down="downCallback" @up="upCallback">
		<!-- 数据列表 -->
		<good-list :list="goods"></good-list>
	</mescroll-body>
</template>

<script>
import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
import mRequest from "@/api/home"
import goodList from './good-list/good-list.vue'
import hccmStore from "@/common/hccm-store.js"
export default {
	mixins: [MescrollMixin], // 使用mixin
	components: { goodList },
	data() {
		return {
			goods: [],
			userInfo: hccmStore.getUser(),
		}
	},
	methods: {
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		upCallback(page) {
			//联网加载数据
			let params = {
				phone: hccmStore.getUserPhone(),
				hospId: hccmStore.getUserHospId(),
				currentPage: page.num,
				pageSize: page.size
			}
			mRequest.getPrescription(params).then(
				res => {
					console.log(res.responseData.total, page.num, page.size)
					this.mescroll.endSuccess(res.responseData.total)
					if (page.num == 1) this.goods = []; //如果是第一页需手动制空列表
					this.goods = this.goods.concat(res.responseData.data); //追加新数据
					console.log(this.goods.length, res.responseData.total)
					this.mescroll.endBySize(this.goods.length, Number(res.responseData.total) + 10); //
					// }
				},
				error => {
					this.mescroll.endErr();
				}
			)
		}
	}
}
</script>
